-
Notifications
You must be signed in to change notification settings - Fork 1.9k
GROOVY-9381: Support async/await like ES7 #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements ES7-like async/await functionality for Groovy, introducing new language keywords async and await along with supporting infrastructure for asynchronous programming.
Key Changes:
- Added
asyncandawaitas new language keywords in the Groovy parser and lexer - Implemented Promise-based asynchronous execution model with
Promise,SimplePromise, and helper classes - Created AST transformation to convert async methods into Promise-returning methods
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/antlr/GroovyLexer.g4 | Adds ASYNC and AWAIT tokens to the lexer |
| src/antlr/GroovyParser.g4 | Adds async modifier and await expression rules to grammar |
| src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | Implements AST building for async/await expressions and method modifiers |
| src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java | Adds ASYNC to invalid modifiers list for constructors |
| src/main/java/org/codehaus/groovy/ast/ModifierNode.java | Registers ASYNC as virtual modifier with no JVM flag |
| src/main/java/org/codehaus/groovy/transform/AsyncASTTransformation.java | Implements transformation of async methods to return Promises |
| src/main/java/groovy/transform/Async.java | Defines @async annotation for marking async methods |
| src/main/java/groovy/util/concurrent/async/*.java | Core async infrastructure including Promise, Awaitable, AsyncHelper, and exception types |
| src/test/groovy/**/*Test.groovy | Comprehensive test coverage for async/await functionality |
| src/test-resources/core/AsyncAwait_01x.groovy | Parser test case for async/await syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * result. | ||
| * | ||
| * @return the computed result | ||
| * @throws AwaitException if the computation was cancelled or completed |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for the await() method's exception is incomplete. It should state 'if the computation was cancelled or completed exceptionally' to clarify that exceptions are thrown on error conditions, not successful completion.
| * @throws AwaitException if the computation was cancelled or completed | |
| * @throws AwaitException if the computation was cancelled or completed exceptionally |
73fe9eb to
208111a
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2324 +/- ##
==================================================
+ Coverage 67.0088% 67.0320% +0.0231%
- Complexity 29326 29416 +90
==================================================
Files 1382 1388 +6
Lines 116604 116804 +200
Branches 20427 20446 +19
==================================================
+ Hits 78135 78296 +161
- Misses 32036 32069 +33
- Partials 6433 6439 +6
🚀 New features to boost your workflow:
|
208111a to
8d4ea6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * | ||
| * @since 6.0.0 | ||
| */ | ||
| public class AsyncHelper { |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The system property 'groovy.async.parallelism' is not documented. Consider adding a comment explaining its purpose and valid values.
| public class AsyncHelper { | |
| public class AsyncHelper { | |
| /** | |
| * The system property "groovy.async.parallelism" controls the parallelism level | |
| * (number of threads) used for the async thread pool. Valid values are positive integers. | |
| * If not set, the default is (number of available processors + 1). | |
| * Setting this value too high may lead to resource exhaustion; too low may reduce concurrency. | |
| */ |
| public class AsyncHelper { | ||
| private static final int PARALLELISM = SystemUtil.getIntegerSafe("groovy.async.parallelism", Runtime.getRuntime().availableProcessors() + 1); | ||
| private static final Executor DEFAULT_EXECUTOR; | ||
| private static int seq; |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static field seq is accessed from multiple threads without synchronization in the thread factory. Use AtomicInteger instead to prevent race conditions.
src/antlr/GroovyLexer.g4
Outdated
| WHILE : 'while'; | ||
| YIELD : 'yield'; | ||
|
|
||
|
|
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extra blank line added at line 490. Remove this unnecessary whitespace to maintain consistent formatting.
8d4ea6f to
1683f60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import static org.apache.groovy.parser.antlr4.GroovyParser.ADD; | ||
| import static org.apache.groovy.parser.antlr4.GroovyParser.ARROW; | ||
| import static org.apache.groovy.parser.antlr4.GroovyParser.AS; | ||
| import static org.apache.groovy.parser.antlr4.GroovyParser.ASYNC; |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The wildcard import at line 157 has been replaced with explicit imports. While this improves clarity by showing exactly which symbols are used, it significantly increases the number of import statements (158-362). Consider whether this trade-off between explicitness and verbosity aligns with the project's style guidelines.
9ab2dee to
448d92a
Compare
dba9bf8 to
e8d5ac1
Compare
71ef10c to
55d94fb
Compare
55d94fb to
5e7e868
Compare
https://issues.apache.org/jira/browse/GROOVY-9381